﻿using System;
using System.Collections.Generic;

namespace СityDelivery
{
	public static class Data
	{
		public static int warehouse;
		public static float[,] ConnectivityMatrix;
		public static float[,] paths;
		public static float loadTime = 30f;
		public static float startTime = 450f;
		public static int speed;
		public static float weightRestriction;
		public static bool parametersFlag = false;
		public static List<int> Shops;


		public struct NodesStruct
		{
			public double NodeId
			{
				get { return nodeId; }
			}
			double nodeId;

			public double NodeLat
			{
				get { return nodeLat; }
			}
			double nodeLat;

			public double NodeLon
			{
				get { return nodeLon; }
			}
			double nodeLon;

			public String[] StreetArray
			{
				get { return streetArray; }
			}
			String[] streetArray;


			public NodesStruct(double nodeId, double nodeLat, double nodeLon, string streetArray)
			{
				String[] split = streetArray.Split(new Char[] { '%' });

				this.nodeId = nodeId;
				this.nodeLat = nodeLat;
				this.nodeLon = nodeLon;
				this.streetArray = split;

			}
		};


		public static List<NodesStruct> nodesList = new List<NodesStruct>();
		public static List<pathDescriptionStruct> pathList = new List<pathDescriptionStruct>();

		public static bool checkIfRepeat(double nodeId)
		{
			foreach (NodesStruct item in nodesList)
				if (item.NodeId == nodeId)
				{
					return true;
				}
			return false;
		}

		public static int CalculateWeights(double lat1, double lon1, double lat2, double lon2)
		{

			double x1, x2, y1, y2, z1, z2;
			int result;
			double C = 0.0174532925; // PI/180
			double R = 6378137; // Экваториальный радиус
			x1 = Math.Cos(C * lat1) * Math.Cos(C * lon1);
			x2 = Math.Cos(C * lat2) * Math.Cos(C * lon2);
			y1 = Math.Cos(C * lat1) * Math.Sin(C * lon1);
			y2 = Math.Cos(C * lat2) * Math.Sin(C * lon2);
			z1 = Math.Sin(C * lat1);
			z2 = Math.Sin(C * lat2);
			return result = Convert.ToInt32(R * Math.Acos(x1 * x2 + y1 * y2 + z1 * z2));

		}

		public struct pathDescriptionStruct
		{
			public int TimeFrom
			{
				get { return timeFrom; }
			}
			int timeFrom;

			public int TimeTo
			{
				get { return timeTo; }
			}
			int timeTo;

			public String PlaceFrom
			{
				get { return placeFrom; }
			}
			String placeFrom;

			public String PlaceTo
			{
				get { return placeTo; }
			}
			String placeTo;

			public float Distance
			{
				get { return distance; }
			}
			float distance;


			public pathDescriptionStruct(int timeFrom, int timeTo, String placeFrom, String placeTo, float distance)
			{
				this.timeFrom = timeFrom;
				this.timeTo = timeTo;
				this.placeFrom = placeFrom;
				this.placeTo = placeTo;
				this.distance = distance;
			}
		};

		public struct shopsInfo
		{
			public int ShopId
			{
				get { return shopId; }
			}
			int shopId;

			public float ShopWeight
			{
				get { return shopWeight; }

			}
			float shopWeight;

			public float ShopTime
			{
				get { return shopTime; }
			}
			float shopTime;

			public shopsInfo(int shopId, float shopWeight, float shopTime)
			{
				this.shopId = shopId;
				this.shopWeight = shopWeight;
				this.shopTime = shopTime;

			}
		};

		public static List<shopsInfo> shopsInfoList = new List<shopsInfo>();
	}
}